home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
comm
/
www
/
HTTX.lha
/
AWeb
/
HTTXPlugin.awebrx
< prev
next >
Wrap
Text File
|
1997-07-16
|
6KB
|
290 lines
/*
Convert current document to TEXT using HTTX
$VER: HTTXPlugin 2.0 (1.5.97) by Gabriele Favrin (favrin@tin.it)
*/
Options Results
Options failat 999
Parse ARG mode mode_data .
'GetCFG TEMPPATH VAR' prefs_temppath
req_title = '"Save as text"'
temp_out = prefs_temppath"temp_HTTXP_Output.txt"
temp_name = prefs_temppath"temp_HTTXP_file"
eol = '0A'x
trg = ""
del_list = prefs_temppath"temp_HTTXP_#?"
force = ""
writeflag = "W"
string = "HTTXPlugin V2.0"||eol||eol
option = ""
prefs_info = 0
prefs_preview= 0
prefs_report = 1
prefs_savedir= "ram:"
Call readcfg()
If (mode == "TARGET") then
trg="TARGET" mode_data
'Get URL VAR' doc_url trg
org_url=doc_url
'GetCFG HTMLMODE'
If result == 0 then
frms.0=0
else
'Get FRAMES ALL' trg 'STEM' frms
If (frms.0 = 0) then do
If getName() == 1 then do
Call SaveHTML()
Call Convert()
Call CleanUp()
End
End
else do
prefs_report=0
'Request' req_title '"Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"'
If rc == 5 then exit()
option=result
If option == 1 then do
If getName() == 0 then do
exit 0
End
End
do ct=1 for frms.0
doc_url=frms.ct.url
trg="TARGET="frms.ct.id
If option == 1 then do
If ct > 1 then do
writeflag="A"
string=eol||eol||"----"||eol||eol
End
Call SaveHTML()
Call Convert()
Call CleanUp()
End
else do
'Open "'frms.ct.url'"'
'Wait "'frms.ct.url'"'
'Request' req_title '"Convert this frame?" _Yes|_No|_Cancel'
If rc == 5 then do
Call CleanUp()
'Open "'org_url'"'
exit()
End
If result == 1 then do
trg=""
string = "HTTXPlugin V2.0"||eol||eol
If getName() == 1 then do
Call SaveHTML()
Call Convert()
Call CleanUp()
End
End
End
End
If option == 1 then do
If prefs_preview == 1 then do
If preview() == 1 then do
Call displayOutput()
End
End
else do
Call displayOutput()
End
Call CleanUp()
End
else do
if option == 2 then do
'Open "'org_url'"'
end
end
End
exit 0
CleanUp:
address command 'C:Delete >NIL: QUIET' del_list
last_slash_pos=LastPos('/', save_file)
if last_slash_pos == 0 then do
pos_colon=Pos(':', save_file)
if prefs_savedir ~= left(save_file, pos_colon) then do
prefs_savedir=left(save_file, pos_colon)
address command 'SetEnv HTTXPlugin.savedir "'prefs_savedir'"'
end
end
else do
if prefs_savedir ~= left(save_file, last_slash_pos) then do
prefs_savedir=left(save_file, last_slash_pos)
address command 'SetEnv HTTXPlugin.savedir "'prefs_savedir'"'
end
end
return
SaveHTML:
'SaveAs "'temp_name'" NOICON' trg
If rc ~= 0 then do
'Request req_title "Error while saving HTML on temporary path*N *N'prefs_temppath'" _Ops'
exit 0
End
return
GetName:
html_name=Translate(doc_url,,'`"=#?/:;\*%')
html_name=Translate(html_name,,"'")
html_name=Word(html_name, Words(html_name))
'RequestFile 'req_title' FILE="'prefs_savedir||html_name'.txt" SAVEMODE'
If (rc == 5) then return 0
save_file=result
If (Right(save_file, 1) == ":") | (Right(save_file, 1) == "/") then
save_file=save_file||html_name'.txt'
html_name=prefs_temppath||html_name
return 1
convert:
'Get MIME VAR' mtype trg
If (Upper(mtype) == "TEXT/HTML") then
drop force
else
force=""
Call PrepareFile()
res=httx()
If (res == 212) then do
'Request 'req_title' "File is not html! Save anyway?" "_Save|_Cancel"'
If (rc ~= 5) then do
address command 'C:Copy "'temp_name'" "'save_file'"'
prefs_report=0
res=0
Call displayOutput()
End
End
else do
If option ~= 1 then do
If (res ~= 0) then do
del_list=del_list '"'save_file'"'
If option ~= 2 then do
Call displayOutput()
End
End
else do
If prefs_preview == 1 then do
If preview() == 1 then do
If option ~= 2 then do
Call displayOutput()
End
End
End
else do
If option ~= 2 then do
Call displayOutput()
End
End
End
End
End
return
httx:
address command 'plugins/httx/HTTX >'temp_out' "'temp_name'" "'save_file'" APPEND' force
return rc
displayOutput:
If (prefs_report == 1) then do
'Open "file://localhost/'temp_out'" RELOAD'
'Wait "file://localhost/'temp_out'"'
End
else do
If (res == 0) then do
'Request 'req_title' "File saved as*N'save_file'" _Ok! NOWAIT'
End
else do
'Request 'req_title' "Error 'rc'" _Ok! NOWAIT'
End
End
return
preview:
'Get SCREEN VAR' prefs_screen
address command 'SYS:Utilities/Multiview 'save_file' pubscreen='prefs_screen
drop result
'Request 'req_title' "File converted." "_Ok|_Delete"'
If (result ~= 1) then do
del_list=del_list '"'save_file'"'
End
return result
PrepareFile:
If Open(fp, save_file, writeflag) then do
If (prefs_info == 1) then do
'Get INFO STEM' infos trg
If (infos.0 > 0) then do
string=string||eol||"Header:"||eol
do ctx=1 for infos.0
If (infos.ctx.type ~= "CACHE") then do
string=string||infos.ctx.value||eol
If infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url
End
End
End
End
WriteCH(fp, string)
Call Close(fp)
End
return
readcfg:
If Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do
cfg=ReadLN(rcfg_fp)
If Left(cfg, 6) == "prefs_" then do
interpret translate(strip(cfg), ';',' ')
prefs_savedir=Translate(prefs_savedir, ' ', ';')
End
Call Close(rcfg_fp)
End
If Open(rcfg_fp, 'ENV:HTTXPlugin.savedir', 'R') then do
prefs_savedir2=ReadLN(rcfg_fp)
If prefs_savedir2 ~= "" then prefs_savedir=prefs_savedir2
Call Close(rcfg_fp)
End
return